/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#include "StdAfx.h"
#include "../guidefaults.h"
#include "../Label.h"

namespace gui {

Label::Label(void)
:	Component(), 
	m_sText(""), 
	m_eAlignment(LEFT)
{
}

Label::Label(const std::string &text, eTextAlign align)
:	Component(), 
	m_sText(text), 
	m_eAlignment(align)
{
}

Label::~Label(void)
{}

void Label::setText(const std::string &text)
{
	m_sText = text;
	//valueChanged(this);
}

const std::string& Label::getText() const
{
	return m_sText;
}

void Label::displayString(const std::string &_str) 
{
	m_sText = _str;
}

void Label::draw()
{
	if (bVisible) {
		vRealPos = getAbsolutePosition();
		eAlign align;
		if (m_eAlignment == LEFT)
			align = FONT_LEFT;
		else if (m_eAlignment == CENTER) 
			align = FONT_CENTER;
		else if (m_eAlignment == RIGHT) 
			align = FONT_RIGHT;

		//pRenderer->drawRect(vRealPos.x, vRealPos.y, vDim.x, vDim.y, vBorderColor);
		// Draw the label
		//font->print(m_sText, vRealPos.x, vRealPos.y + static_cast<int>(vDim.y*0.5f) - static_cast<int>(iRowSize*0.5f), 0, align, vDim.x, vDim.y, vTextColor);
		font->print(m_sText, vRealPos.x, vRealPos.y, 0, align, vDim.x, vDim.y, vTextColor);
	}
}

void Label::matchSizeToText() {
	vDim.x = font->getLength(m_sText);
	vDim.y = font->getSize() + 2;
}

} // namespace
